package com.czyxy.repository;

import com.czyxy.domain.Clazz;
import com.czyxy.domain.StudentFee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;

/**
 * Created by mike on 8/31/17.
 */
@Repository
public class OtherRepositoryImpl implements OtherRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
    }

    @Override
    public List<Clazz> getClassesByHelpcode(String helpcode) {
        helpcode=(helpcode==null?"%":"%"+helpcode+"%");
        final List<Clazz> classes = new ArrayList<>();
        String sql = "select DISTINCT class_code,class_name from student_fee where (class_code like '"+helpcode+"' ) or (class_name like '"+helpcode+"')";
        jdbcTemplate.query(sql,(RowCallbackHandler)(rs)->{
            Clazz clazz = new Clazz();
            clazz.setCode(rs.getString("class_code"));
            clazz.setName(rs.getString("class_name"));
            classes.add(clazz);
        });
        return classes;
    }

}
